package com.yanqu.road.server.manger.activity.guagifts.service;

import com.google.protobuf.InvalidProtocolBufferException;
import com.yanqu.road.pb.activity.GuaGiftsProto;
import com.yanqu.road.pb.activity.QixiProto;
import com.yanqu.road.pb.syncMessage.SyncMessage;
import com.yanqu.road.server.game.service.IGameServiceCommand;
import com.yanqu.road.server.manger.activity.guagifts.GuaGiftsMgr;
import com.yanqu.road.server.manger.activity.qixi.QixiMgr;
import com.yanqu.road.sync.message.SyncResponse;

public class GuaSendGiftServiceCmd implements IGameServiceCommand {
    @Override
    public SyncResponse execute(SyncMessage.Request request) throws InvalidProtocolBufferException {
        SyncResponse syncResponse = new SyncResponse();
        GuaGiftsProto.GuaGiftsSendGiftReqMsg reqMsg = GuaGiftsProto.GuaGiftsSendGiftReqMsg.parseFrom(request.getDataBytes());

        GuaGiftsProto.CrossGuaGiftsSendGiftRespMsg.Builder backMsg = GuaGiftsMgr.receiveGift(request.getRawServerId(), request.getSenderId(), reqMsg.getTargetUserId(), reqMsg.getGiftId(), reqMsg.getGiftCount(), reqMsg.getContent());
        if (backMsg == null) {
            backMsg = GuaGiftsProto.CrossGuaGiftsSendGiftRespMsg.newBuilder();
            backMsg.setRet(-1);
            backMsg.setGiftId(reqMsg.getGiftId());
            backMsg.setGiftCount(reqMsg.getGiftCount());
            backMsg.setTargetUserId(reqMsg.getTargetUserId());
        }

        syncResponse.setResponseBuilder(backMsg);
        return syncResponse;
    }
}
